/*
 * WallSheetPreviewPanel.java
 *
 * Created on November 3, 2007, 2:07 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package jia.editor.widgets;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author gryffonx
 */
public class WallSheetPreviewPanel extends JPanel {
    BufferedImage bufImage;
    private Rectangle map;
    
    /** Creates a new instance of WallSheetPreviewPanel */
    public WallSheetPreviewPanel(String imageFileName) {
        try { 
            this.setBackground(Color.BLACK);
            bufImage = ImageIO.read(new File("resources/images/walls/" + imageFileName));
        } catch(Exception e) {
            throw new RuntimeException(e);
        }
        
        
    }
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D)g;

        map = new Rectangle(1, 1, (bufImage.getWidth()), (bufImage.getHeight()));
        g2d.setPaint(new TexturePaint(bufImage, map));
        g2d.fill(map);
    }
    
    public static void main(String[] args){
        JFrame testFrame = new JFrame();
        
        WallSheetPreviewPanel pnl = new WallSheetPreviewPanel("stoneWall01.png");
        testFrame.setContentPane(pnl);
        testFrame.setVisible(true);
    }
    
}
